import java.util.LinkedList;
import java.util.Queue;

public class CompletedTree {
    static class TreeNode{
        public char val;
        public TreeNode left;
        public TreeNode right;

        public TreeNode(char val) {
            this.val = val;
        }
    }
    boolean isCompleteTree(TreeNode root){
        if (root == null){
            return true;
        }
        Queue<TreeNode> queue = new LinkedList<>();
        queue.offer(root);
        while (!queue.isEmpty()){//将所有元素入队，直到读取到null
            TreeNode cur = queue.poll();
            if (cur != null){
                queue.offer(cur.left);
                queue.offer(cur.right);
            }else {
                break;
            }
        }
        while (!queue.isEmpty()){//判断此时队中除了null还有没有别的元素
            TreeNode tmp = queue.poll();
            if (tmp != null){//如果有，说明不为完全二叉树
                return false;
            }
        }
        return true;
    }
}
